func maxSubArray(nums []int) int {
    count := 0
    result := nums[0]
    for i:=0; i<len(nums); i++ {
        count += nums[i]
        result = max(count, result)
        if count<0 {
            count = 0
        }
    }
    return result
}

func max(a int, b int) int {
    if a > b {
        return a
    }
    return b
}